package com.ternnetwork.batch.writer;

import org.springframework.batch.item.ItemWriter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.FileSystemResource;

import com.ternnetwork.batch.item.excel.ExcelItemWriter;
import com.ternnetwork.batch.item.mapper.excel.ModelToExcelRowMapper;
import com.ternnetwork.batch.mapper.TestUserToExcelRowMapper;
import com.ternnetwork.batch.model.TestUser;


@Configuration
/**
 * 
 * @author xuwenfeng
 *
 */
public class TestUserExcelItemWriterConfiguration {
	
	
	
	
	
	@Bean("testUserExcelItemWriter")
	public ItemWriter<TestUser> getItemWriter(){
		
		
		ExcelItemWriter<TestUser> excelItemWriter=new ExcelItemWriter<TestUser>();
		 //文件名输出路径
		 FileSystemResource fileUrlResource = new FileSystemResource("/Users/xuwenfeng/Documents/ws/avocado-cloud-parent/avocado-cloud-batch/src/main/resources/test-data/user_excel.xls");
		
		 
		 excelItemWriter.setResource(fileUrlResource);
		 
		 excelItemWriter.setHeader("ID,姓名,年龄");
		 
		 
		 excelItemWriter.setRowMapper(getRowMapper());
		
		
		return excelItemWriter;
		
	}
	
	
	public ModelToExcelRowMapper getRowMapper() {
		
		return new TestUserToExcelRowMapper();
	}

}
